(function(){"use strict";BX.namespace("BX.Grid");BX.Grid.PinHeader=function(t){this.parent=null;this.table=null;this.header=null;this.container=null;this.parentNodeResizeObserver=null;this.init(t)};BX.Grid.PinHeader.prototype={init:function(t){this.parent=t;this.rect=BX.pos(this.parent.getHead());this.gridRect=BX.pos(this.parent.getTable());var e=BX.Grid.Utils.getBySelector(document,"#workarea-content",true);if(!e){e=this.parent.getContainer().parentNode;e=!!e?e.parentNode:e}if(!!e){this.parentNodeResizeObserver=new BX.ResizeObserver(BX.proxy(this.refreshRect,this));this.parentNodeResizeObserver.observe(e)}this.create(true);document.addEventListener("scroll",BX.proxy(this._onScroll,this),BX.Grid.Utils.listenerParams({passive:true}));document.addEventListener("resize",BX.proxy(this._onResize,this),BX.Grid.Utils.listenerParams({passive:true}));BX.addCustomEvent("Grid::updated",BX.proxy(this._onGridUpdate,this));BX.addCustomEvent("Grid::resize",BX.proxy(this._onGridUpdate,this));BX.bind(window,"resize",BX.proxy(this._onGridUpdate,this))},refreshRect:function(){this.gridRect=BX.pos(this.parent.getTable());this.rect=BX.pos(this.parent.getHead())},_onGridUpdate:function(){var t=this.isPinned();BX.remove(this.getContainer());this.create();t&&this.pin();this.table=null;this.refreshRect();BX.onCustomEvent(window,"Grid::headerUpdated",[])},create:function(t){var e=BX.Grid.Utils.getByTag(this.parent.getHead(),"th");var i=BX.clone(this.parent.getHead());var n=BX.Grid.Utils.getByTag(i,"th");var r=function(){e.forEach(function(t,i){var r=BX.width(t);if(i>0){r-=parseInt(BX.style(t,"border-left-width"));r-=parseInt(BX.style(t,"border-right-width"))}n[i].firstElementChild&&(n[i].firstElementChild.style.width=r+"px");if(e.length-1>i){n[i].style.width=r+"px"}})};t?setTimeout(r,0):r();this.container=BX.decl({block:"main-grid-fixed-bar",mix:"main-grid-fixed-top",attrs:{style:"width: "+BX.width(this.parent.getContainer())+"px"},content:{block:"main-grid-table",tag:"table",content:i}});this.container.hidden=true;this.parent.getWrapper().appendChild(this.container)},getContainer:function(){return this.container},getFixedTable:function(){return this.table||(this.table=BX.Grid.Utils.getByTag(this.getContainer(),"table",true))},pin:function(){!!this.getContainer()&&(this.getContainer().hidden=false);BX.onCustomEvent(window,"Grid::headerPinned",[])},unpin:function(){!!this.getContainer()&&(this.getContainer().hidden=true);BX.onCustomEvent(window,"Grid::headerUnpinned",[])},stopPin:function(){BX.Grid.Utils.styleForEach([this.getContainer()],{position:"absolute",top:this.gridRect.bottom-this.rect.height-this.gridRect.top+"px","box-shadow":"none"})},startPin:function(){BX.Grid.Utils.styleForEach([this.getContainer()],{position:"fixed",top:0,"box-shadow":""})},isPinned:function(){return!this.getContainer().hidden},_onScroll:function(){var t=0;if(this.scrollRect){t=this.scrollRect.scrollTop}else{if(document.scrollingElement){this.scrollRect=document.scrollingElement}else{if(document.documentElement.scrollTop>0){this.scrollRect=document.documentElement}else if(document.body.scrollTop>0){this.scrollRect=document.body}}}if(this.gridRect.bottom>t+this.rect.height){this.startPin();if(this.rect.top<=t){!this.isPinned()&&this.pin()}else{this.isPinned()&&this.unpin()}}else{this.stopPin()}},_onResize:function(){this.rect=BX.pos(this.parent.getHead())}}})();
//# sourceMappingURL=pin-header.map.js